package com.masterclient.app.modules.firstpager.fragments.contract;

import com.eoner.baselib.presenter.ThrowableConsumer;
import com.masterclient.app.httpservice.RetrofitUtil;
import com.eoner.baselibrary.bean.firstpager.NewGoodDiscountBean;

import io.reactivex.Observable;
import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;

/**
* Created by TMVPHelper on 2017/08/15
*/
public class NewGoodsPresenter extends NewGoodsContract.Presenter{

    @Override
    public void getNewGoodDiscount() {
        Observable<NewGoodDiscountBean> observable = RetrofitUtil.getInstance().getNewGoodDiscount();
        Disposable disposable = toSubscribe(observable, new Consumer<NewGoodDiscountBean>() {
            @Override
            public void accept(@NonNull NewGoodDiscountBean bean) throws Exception {
                if("0".equals(bean.getCode())){
                    mView.showNewGoodDiscount(bean.getData());
                }else {
                    mView.showFailed();
                }
            }
        }, new ThrowableConsumer());

        mRxManager.add(disposable);
    }
}